<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>$event事件对象</title>
  <script src="./lib/vue.js"></script>
</head>

<body>
  <div id="app">
    <h2>当前计数：{{counter}}</h2>
    <!-- vue 提供了内置变量，名字叫做 $event，它就是原生 DOM 的事件对象 e -->
    <button @click='Numadd($event,1)'>+</button>
    <button @click='Numsub($event,1)'>-</button>
  </div>
  <script>
    const obj = {
      counter: 0
    }
    let app = new Vue({
      el: '#app',
      data: obj,
      methods: {
        // ()中可以传参
        Numadd(e, n) {
          this.counter += n;
          console.log('counter+n');
          console.log(e);

          if(this.counter%2==1){
            e.target.style.backgroundColor = 'skyblue'
          }else{
            e.target.style.backgroundColor = 'pink'
          }
        },
        Numsub(e, n) {
          this.counter -= n;
          console.log('counter-n');
          console.log(e);

          if(this.counter%2==1){
            e.target.style.backgroundColor = 'skyblue'
          }else{
            e.target.style.backgroundColor = 'pink'
          }
        }
        
      }
    })
  </script>
</body>

</html>